//
//  HomePulldownView.m
//  Btpin
//
//  Created by Vic on 2019/3/16.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "HomePulldownView.h"
#import "CQTopBarViewController.h"
#import "LYRecomedController.h"
#import "LYAreaController.h"
#import "LYCompanyController.h"
#import "LYClaimController.h"
#import "LYRecomendCell.h"

@interface HomePulldownView ()

@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) CQTopBarViewController *topBar;

@property (nonatomic, strong) NSArray *recomendArray;
@property (nonatomic, strong) NSArray *areaArray;
@property (nonatomic, strong) NSArray *companyArray;
@end

@implementation HomePulldownView

- (NSArray *)recomendArray {
    if (!_recomendArray) {
        _recomendArray =@[@{@"name":@"推荐",@"id":@"1"},@{@"name":@"最新",@"id":@"2"}];
    }
    return _recomendArray;
}

- (NSArray *)areaArray {
    if (!_areaArray) {
        _areaArray = @[@{@"name":@"附近",@"id":@"1",@"child":@[@{@"name":@"距离不限",@"id":@"1"},@{@"name":@"1公里",@"id":@"2"},@{@"name":@"3公里",@"id":@"3"}]},@{@"name":@"商圈",@"id":@"2",@"child":@[@{@"name":@"海淀区",@"id":@"1"},@{@"name":@"朝阳区",@"id":@"2"},@{@"name":@"通州区",@"id":@"3"}]}];
    }
    return _areaArray;
}

- (NSArray *)companyArray {
    if (!_companyArray) {
        _companyArray = @[
                          @{@"name":@"公司规模",@"id":@"1",@"child":@[@{@"name":@"少于15热",@"id":@"1"},@{@"name":@"15-20人",@"id":@"2"},@{@"name":@"20-30人",@"id":@"3"},@{@"name":@"30-40人",@"id":@"4"}]},
                          @{@"name":@"融资情况",@"id":@"2",@"child":@[@{@"name":@"未融资",@"id":@"1"},@{@"name":@"天使轮",@"id":@"2"},@{@"name":@"A轮",@"id":@"3"}]},
                          @{@"name":@"公司行业",@"id":@"3",@"child":@[@{@"name":@"区块链",@"id":@"1"},@{@"name":@"互联网",@"id":@"2"},@{@"name":@"电子商务",@"id":@"3"}]}];
    }
    return _companyArray;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = COLOR_OF_WHITE;
        [self createSubview];
    }
    return self;
}

- (void)createSubview {
    NSString * dicStr = [[NSBundle mainBundle] pathForResource:@"data.json" ofType:nil];
    NSData *data = [[NSData alloc] initWithContentsOfFile:dicStr];
    NSDictionary *dataDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
    __weak typeof(self) weakSelf = self;
    self.topBar = [[CQTopBarViewController alloc] init];
    self.topBar.sectionTitles = @[@"推荐", @"区域", @"公司", @"要求"];
    
    //推荐
    LYRecomedController *recommendVC = [[LYRecomedController alloc] init];
    recommendVC.dataArray = self.recomendArray;
    recommendVC.block = ^(NSDictionary *dic){
        [weakSelf recomdendItemClick:dic];
    };
    
    //区域
    LYAreaController *areaVC = [[LYAreaController alloc] init];
    areaVC.dataArray = self.areaArray;
    areaVC.blcok = ^(NSDictionary *dic1,NSDictionary *dic2){
        [weakSelf areaItemClick:dic1 areaDic:dic2];
    };
    
    //公司
    LYCompanyController *companyVC = [[LYCompanyController alloc] init];
    companyVC.dataArray = self.companyArray;
    companyVC.block = ^(NSArray *array){
        [weakSelf companyItemClick:array];
    };
    
    //要求
    LYClaimController *claimVC = [[LYClaimController alloc] init];
    claimVC.dataDic = dataDic;
    
    self.topBar.pageViewClasses = @[recommendVC, areaVC, companyVC, claimVC];
    self.topBar.selectSegmentImage = @"pulldown_select";
    self.topBar.segmentImage = @"pulldown_unselect";
    self.topBar.selectedTitleTextColor = [UIColor redColor];
    self.topBar.titleTextColor = THEMECOLOR_OF_TEXT_333333;
//    [self addChildViewController:self.topBar];
    [self addSubview:self.topBar.view];
}

#pragma mark -- Action
- (void)recomdendItemClick:(NSDictionary *)dic {
    NSLog(@"%@", dic[@"name"]);
}

- (void)areaItemClick:(NSDictionary *)dic1  areaDic:(NSDictionary *)dic2 {
    NSLog(@"%@", [NSString stringWithFormat:@"%@-%@",dic1[@"name"],dic2[@"name"]]);
}

- (void)companyItemClick:(NSArray *)array {
    NSString *str = @"";
    for (NSDictionary *dic in array) {
        str = [NSString stringWithFormat:@"%@-%@",str,dic[@"name"]];
    }
    NSLog(@"%@", str);
}

@end
